home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / vbcc / machines / amiga68k / libsrc / stdio / fopen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-17  |  1.0 KB  |  37 lines

  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include <limits.h>
  4. #include <stdarg.h>
  5. #include <stdlib.h>
  6.  
  7. #include <dos/dos.h>
  8.  
  9. extern FILE *_firstfile,*_lastfile;
  10.  
  11. /*  oeffnet Dateien */
  12. /*  noch sehr eingeschraenkt    */
  13. FILE *fopen(const char *name,const char *mode)
  14. {
  15.     FILE *f;long amigamode=0;int append;
  16.     if(*mode=='w') amigamode=MODE_NEWFILE; else amigamode=MODE_OLDFILE;
  17.     if(*mode=='a') append=1; else append=0;
  18.     if(!(f=malloc(sizeof(FILE)))) return(0);
  19.     f->count=0;
  20.     f->base=0;
  21.     f->bufsize=0;
  22.     f->next=0;
  23.     if(*mode=='r') f->flags=_READABLE; else f->flags=_WRITEABLE;
  24.     if(*mode=='b') mode++;
  25.     if(*mode=='+') {f->flags|=_READABLE|_WRITEABLE;amigamode=MODE_READWRITE;}
  26.     f->filehandle=(char *)Open(name,amigamode);
  27.     if(!f->filehandle){free(f);return(0);}
  28.     if(IsInteractive(f->filehandle)) f->flags|=_LINEBUF;
  29.     if(_lastfile){
  30.         _lastfile->next=f;f->prev=_lastfile;_lastfile=f;
  31.     }else{
  32.         _firstfile=_lastfile=f;
  33.     }
  34.     if(append) fseek(f,0,SEEK_END);
  35.     return(f);
  36. }
  37.